/**
 * 
 */
package com.glodon.paas.account.dao.redis;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.glodon.paas.account.dao.domain.OAuthTokenEntity;

/**
 * @author hankl
 * @date  2012-11-2
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = {
		"classpath:spring-config-test.xml",
		"classpath:paas-account-dao-mysql.xml"		
		})
public class TokenDaoRedisImplIT {
	
    @Autowired	
    private OAuthTokenEntity token;
	
	@Autowired
	 private OAuthTokenDaoRedisImpl redisTokenDao; 
	
	@Autowired 
	private TokenDaoRedisImpl tokenDao;
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		redisTokenDao.saveToken(token);
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		redisTokenDao.removeToken(token.getValue());
	}

	/**
	 * Test method for {@link com.glodon.paas.account.dao.redis.TokenDaoRedisImpl#getAccessTokens(java.lang.String)}.
	 */
	@Test
	public void GetAccessTokens() {
		String uid = token.getUserId();		
		List<OAuthTokenEntity> tokenList = tokenDao.getAccessTokens(uid);		
		assertThat(tokenList.iterator().next().getValue(),is(token.getValue()));
	}

}
